package com.jhgsys.internal.common.runner;

import lombok.extern.slf4j.Slf4j;
import net.sf.ehcache.CacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

/**
 * @author MrBird
 */
@Slf4j
@Component
public class FebsShutdownListener implements ApplicationListener<ContextClosedEvent> {

    @Autowired
    private CacheManager cacheManager;

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        // 当Spring Boot应用程序关闭时，这个方法会被调用
        if (cacheManager != null) {
            cacheManager.shutdown();
            log.info("CacheManager：已关闭");
        }
    }
}